﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class CompanyPartners : YuanlinUserControl,
        IReplyConverter<CompanyPartnerCategoryReply, GetListOperation>
    {
        protected Repeater list;
        protected Repeater category;
        private EntityList companyPartnerCategory;
        private int categoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryId);
        public string greenNum = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.GreenNum);

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            CompanyPartnerCategoryListRequest request = new CompanyPartnerCategoryListRequest();
            request.UserId = UserIdFromGreenNum;
            request.PageIndex = 0;
            request.PageSize = 1000;
            requestBinders.Add(RequestHelper.BuildGetCompanyPartnerCategoryListRequest(this, request));
        }

        private void BindData()
        {
            CompanyPartnerCategory header = new CompanyPartnerCategory();
            header.Title.Value = "所有类别";
            companyPartnerCategory.Insert(0, header);

            category.DataSource = companyPartnerCategory;
            category.DataBind();

            CompanyPartnerListRequest request1 = new CompanyPartnerListRequest();
            request1.UserId = UserIdFromGreenNum;
            request1.CategoryId = categoryId;
            request1.PageIndex = 0;
            request1.PageSize = 100;
            list.DataSource = BusinessManager.GetCompanyPartnerList(RequestHelper.BuildGetCompanyPartnerListRequest(request1));
            list.DataBind();
        }

        #region IReplyConverter<CompanyPartnerCategoryReply,GetListOperation> Members

        public void ConvertReply(CompanyPartnerCategoryReply reply, GetListOperation operation)
        {
            if (reply != null)
            {
                companyPartnerCategory = reply.EntityList;

                if (!IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
